package com.c2b.algorithm.leetcode.base;

import java.util.Arrays;

/**
 * @author c2b
 * @since 2024/3/25 9:37
 */
public class LC0322 {

    static class Solution {
        public int coinChange(int[] coins, int amount) {
            int max = amount + 1;
            int[] dp = new int[max];
            Arrays.fill(dp, max);
            dp[0] = 0;
            // 计算 0 金额到amount 金额，所有的可能性
            for (int currAmount = 1; currAmount <= amount; currAmount++) {
                for (int coin : coins) {
                    if (coin <= currAmount) {
                        dp[currAmount] = Math.min(dp[currAmount], dp[currAmount - coin] + 1);
                    }
                }
            }
            return dp[amount] > amount - 1 ? -1 : dp[amount];
        }
    }
}
